
/**
 * MainDo
 * 功能：
 * 基本的类型转换
 * 从数据库获取基本数据
 * author：shinion
 */

/**
 * 数据操作类，
 * 进行各类数据操作
 */
MainDo = {

};

//根据icon,获得图片
MainDo.getIcon = function(iconName){
	var defaultImgPath= globalConfig.webPath + "/image/default.png";
	var str = iconName.split((/[-]/));
	var returnImgPath;
	if(str[1]){
		//解析正确
		returnImgPath = globalConfig.webPath + "/image/" +str[1] + ".png";
		return returnImgPath;
	}else{
		//解析icon格式错误，返回默认图片
		return defaultImgPath;
	}
};

/**
 * 根据功能name，获取相应的图片
 */
MainDo.getImg = function(name){
	var path = globalConfig.webPath + "/image2/";
	var returnImgPath;
	switch(name){
		case"车辆监控":
		returnImgPath = path + "onlinecar1.png";
		break;

		case"报警处理":
		returnImgPath = path + "alarm1.png";
		break;

		case"实时视频":
		returnImgPath = path + "realVideo.png";
		break;

		case"历史视频":
		returnImgPath = path + "history.png";
		break;

		case"报表管理":
		case"统计报表":
		returnImgPath = path +  "report1.png";
		break;

		case"基础资料":
		returnImgPath = path + "editInfo1.png";
		break;

		case"用户管理":
		returnImgPath = path + "user1.png";
		break;

		case"系统管理":
		case"系统设置":
		returnImgPath = path + "config1.png";
		break;

		case"退出":
		returnImgPath = path + "exit1.png";
		break;

		default:
		returnImgPath = path + "fun-default.png";
		break;
	}
	return returnImgPath;

};


MainDo.leftInit = function(data){
	var tt = $('#treeTab'); //如果tab已经存在,则选中并刷新该tab   
	if(tt != undefined){
		tt.tabs('select', "功能面板");
	}       

	//更改面板title，暂无效
	// var leftMenus = $("#leftMenus");
	// if((leftMenus != undefined) && data){
	// 	leftMenus.attr("title",data.text);
	// }//end change

	var leftUp = $("#leftUp");
	var leftDown = $("#leftDown");
	if(leftUp != undefined){
		leftUp.empty();
	}else{
		return false;
	}
	if(leftDown != undefined){
		//leftDown.css("display","none");
		leftDown.hide();

	}else{
		return false;
	}	
	return true;
};



/**
 * 基本数据类
 * 用于获取和保存全局基本数据
 */


MyBasicData = {};
MyBasicData.webPath = "";

/**
 * 初始化，完成基本的数据下载
 */
MyBasicData.init = function(webPath){
	this.webPath = webPath;
	try {
		this.getAlarmSourcesData();//获取报警来源和报警类型
		this.getProcessedRemarkData();//获取报警处理方式
		// console.log("获取基本数据成功");
	} catch (error) {
		console.error("基本数据初始化失败："+error);
	}
	
};
/**
 * 获取报警来源和报警类型基本数据
 */
MyBasicData.getAlarmSourcesData = function () {
	var me = this;
	//定时器，获取报警来源和报警类型数据
	$(document).oneTime("1s", "getAlarmSourceData", function () {
		// console.log("定时方法开始");
		try {
			//获取报警数据
			$.ajax({
				type: "post",//请求方式
				url: me.webPath+"/activeSafeAlarm/getAlarmSources.action",
				data: null,
				contentType: "application/json;charset=utf-8",
				success: function (data) {
					//处理数据
					disposeData(data);
					//获取数值，赋值
					window.localStorage.setItem("alarmSourceList", JSON.stringify(data));
					// console.log("获取报警来源和报警类型信息数据成功");
				}
			});
		} catch (error) {
			console.error("获取报警来源和报警类型信息数据错误" + error);
		}
	});
};

//处理数据，给数据加上索引
function disposeData(data){
	try {
		var length = data.length;
		if(length > 0){
			for(var i=0 ; i<length ; i++){
				data[i].index = i;
			}
		}
	} catch (error) {
		console.error("处理数据错误:"+error);
	}
}

/**
 * 获取处理方式和处理状态基本数据描述
 */
MyBasicData.getProcessedRemarkData = function(){
	var me = this;
	//定时器，获取报警处理方式和处理状态信息
	$(document).oneTime("2s", "getProcessedData", function () {
		// console.log("定时方法开始");
		try {
			//获取数据
			$.ajax({
				type: "post",//请求方式
				url: me.webPath+"/activeSafeAlarm/getAlarmProcessedRemarkData.action",//请求地址
				data: null,
				contentType: "application/json;charset=utf-8",
				success: function (data) {
					//获取数值，赋值
					// console.log(data);
					window.localStorage.setItem("alarmProcessedData",JSON.stringify(data));
					// console.log("获取报警处理信息数据成功");//测试输出
					
				}
			});
		} catch (error) {
			console.error("获取报警处理信息数据错误" + error);
		}
	});
};






//绑定事件
function leftAddEvt(data){
	if(data != undefined){
		var left = $("#" + data.id);
		if(left != undefined){
			//console.log("leftAddEvt->"+data.id + " ,"+ data.text);
			left.css("cursor","pointer");
			left.bind("click", data, leftMenuClick);
			left.bind("mouseover",data.id,leftMouseOver);
			left.bind("mouseout",data.id,leftMouseOut);
		}
	}
}

/**
* 左侧功能面板点击事件
*/
function leftMenuClick(evt) {
	if (evt) {
		data = evt.data;
		console.log(data.url);
		switch (data.text) {
			case "百度地图":
				var mapType = "baidu";
				MyMenu.setMapPath(mapType);
				break;
			case "高德地图":
				var mapType = "amap";
				MyMenu.setMapPath(mapType);
				break;
			case "四维地图":
				var mapType = "smart";
				MyMenu.setMapPath(mapType);
				break;
			default:
				addTab(data.text, data.url, data.iconCls);
				
				break;

		}
	}
	// var left = $("#leftMenus");

}

//鼠标移动到元素上事件
function leftMouseOver(evt){
	var left =$("#" + evt.data);
	if(left != undefined){
		//left.css("cursor","pointer");
		left.css("background","skyblue");
	}

	
        									
}

//鼠标从元素上移开事件
function leftMouseOut(evt){
	var left =$("#" + evt.data);
	if(left != undefined){
		left.css("background","");
		//left.css("cursor","default");
	}
}

